<?php

class IndexController extends Zend_Controller_Action
{
	
	private $templateArray;

    public function init()
    {
    	$this->templateArray = array();
    	$this->templateArray['serviceType']='';
    	// Dienst-Übergreifende Vorgaben
    	$this->templateArray['constraints']['metaDatenSchutz'] = '';
		$this->templateArray['constraints']['enddienst'] = '';
		$this->templateArray['constraints']['logging'] = '';
		$this->templateArray['constraints']['trustLevel'] = '';
		$this->templateArray['constraints']['trustArchitektur'] = '';
		$this->templateArray['constraints']['credentialArt'] = '';
		$this->templateArray['constraints']['credentialDynamik'] = '';
		
		// Compliance
		$this->templateArray['constraints']['euRichtlinien'] = '';
		$this->templateArray['constraints']['bundesDatenschutz'] = '';
		$this->templateArray['constraints']['usa'] = '';
		$this->templateArray['constraints']['iso27001Zert'] = '';
		$this->templateArray['constraints']['iso27002'] = '';
		$this->templateArray['constraints']['bsiGrundschutz'] = '';
		$this->templateArray['constraints']['penetrationsTests'] = '';
		$this->templateArray['constraints']['pci'] = '';
		$this->templateArray['constraints']['glba'] = '';
		$this->templateArray['constraints']['hipaa'] = '';
		$this->templateArray['constraints']['qualifikationITSiBe'] = '';
        
		// IAAS
		$this->templateArray['constraints']['closeBoxVM'] = '';
		$this->templateArray['constraints']['minimalTrustedComputingBase'] = '';	
		$this->templateArray['constraints']['trustedPlatformModule'] = '';	
		$this->templateArray['constraints']['geographischerSpeicherOrt'] = '';
		$this->templateArray['constraints']['verschluesselung'] = '';
		$this->templateArray['constraints']['zugriffsrichtlinien'] = '';
		$this->templateArray['constraints']['backupDataRecovery'] = '';
		
      	// PAAS
      	$this->templateArray['constraints']['updaterichtlinien'] = '';
      	
      	// SAAS
      	$this->templateArray['constraints']['commonCriteriaStufe'] = '';
		$this->templateArray['constraints']['nachrichtenIntegritaet'] = '';
		$this->templateArray['constraints']['nachrichtenVertraulichkeit'] = '';
		
		
		
		
        
    }

    public function indexAction()
    {
    	
    	      
    }

    public function adHocRequestAction()
    {
    	
       $this->view->placeholder('box1')->set("Test");
           	
        $services = new ServiceTypesModel();
        
        $rowset = $services->fetchAll();
        $rowsetArray = $rowset->toArray();
        $params = array();
        // Parameter 'serviceTypes' für die View
        
        
       	foreach ($rowsetArray as $key => $value) {
        	        	
         	$this->templateArray['serviceType']['serviceBeschreibung'.$key] = $rowsetArray[$key]['serviceBeschreibung'];
        }
      
       	        
       // Parameter übergeben
        
 	   foreach ($this->templateArray as $key => $value) {
 	   	$this->view->assign($key, $value);
 	   }
 	   
 	   
 	   $this->view->assign('form_action', 'search' );
        
    }
    
    public function searchAction()
    {
    	    	
    	// Array zur Dienst Suche konstruieren
    	
    	$searchArray = $this->templateArray;
    	
    	$searchArray['serviceType'] = $_POST['serviceType'];
    	
    	foreach ($_POST as $key => $value) {
    		
    		//Ohne die Post-Werte 'button_suche' und 'serviceType', da unnötig
    		
    		if($key != 'button_suche' AND $key !='serviceType'){
    			
    			 $searchArray['constraints'][$key]=$value;
    		}
    	}
    	
    	// $searchArray soll statt "on" und "" (von den Checkboxen) "1" bzw. "0" enthalten
    	
    	foreach ($searchArray['constraints'] as $key => $value) {
    		
    			if ($value == "on"){
    				$searchArray['constraints'][$key] = "1";
    			} 
    			elseif ($value == ""){
    				$searchArray['constraints'][$key] = "0";
    			}
    	}
    	
    	
    	
    	require_once __DIR__.'/utilities/ServiceMediator.php';
    	$mediator = new ServiceMediator($searchArray);
    	
    	$result = $mediator->giveMatch();
    	
    	    	    	
    	// Daten an die View übergeben
    	
    	$this->view->result = $result;
    	
    	
    	
    	
    }

    public function loginAction()
    {
        // action body
    }

    public function registerAction()
    {
	
    	if(count($_POST) == 0)     
    	{
    		$this->view->assign('form_action', 'register');
    	}
    	
    	else {
    		
    		if ($_POST['type']=='Dienst Nutzer') {
    			
    			$this->_redirect('/service-user/create');
    		}
    		
    		elseif ($_POST['type'] == 'Dienst Anbieter'){
    			$this->_redirect('/service-provider/create');
    		}
    	}
    }
    
   
    
    



}







